package com.example.finalframe.controller;

import com.example.finalframe.service.intf.FileService;
import com.example.finalframe.common.ApiConstant;
import com.example.finalframe.common.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@RestController
@RequestMapping("/file")
public class FileController {
    @Autowired
    FileService fileStorageService;

    @PostMapping("/upload")
    public ApiResult<String> upload(@RequestParam MultipartFile file) throws IOException {
       if("SUCCESS".equals(fileStorageService.storeFile(file))){
           return ApiResult.success("");
       }else{
            return ApiResult.fail(ApiConstant.RESULT_OTHER_EXCEPTION,"操作失败");
       }
    }
}